package com.cjst.controller.api.weather;

import java.math.BigDecimal;
import java.util.Date;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cjst.pojo.weather.Weather;
import com.cjst.service.weather.WeatherService;
import com.cjst.util.common.DateUtil;
import com.cjst.util.common.ResultCode;
import com.cjst.util.json.ResultObj;

@Controller
@RequestMapping(value="/api/weather")
public class WeatherController {
	protected final Logger log = Logger.getLogger(WeatherController.class);
	@Autowired
	private WeatherService weatherService;
	/**
	 * 获取天气数据
	 * @return
	 */
	@RequestMapping(value="/getWetherData",method = RequestMethod.POST)
	@ResponseBody
	public String getWetherData(String pmTow,String pmTen,String tsp,String noise,String temperature,String temSection,String windSpeed,String windDirection,
			String windPower,Integer weatherCondition,String weatherDescription,String partId,String snNo){
		try {
			Weather wt=new Weather();
			wt.setPmTow(pmTow);
			wt.setPmTen(pmTow);
			wt.setTsp(tsp);
			wt.setNoise(noise);
			wt.setTemperature(temperature);
			wt.setPmTen(pmTow);
			wt.setTemSection(temSection);
			wt.setWindSpeed(windSpeed);
			wt.setWindDirection(windDirection);
			
			wt.setWindPower(windPower);
			wt.setWeatherCondition(weatherCondition);
			wt.setWeatherDescription(weatherDescription);
			wt.setPartId("0ZO9BBV2PFHSERBP86954E49CD2749C0A7ED2C3F03DD9B7D");
			wt.setSnNo(snNo);
			wt.setCreateTime(DateUtil.stringToDate(DateUtil.dateToString(new Date(), "yyyy-MM-dd HH:mm:ss"),"yyyy-MM-dd HH:mm:ss"));
			weatherService.addLocalByid(wt);
			ResultObj robj = new ResultObj(ResultCode.RESULT_SUCCESS, "success");
			return robj.toString();
		}catch (Exception e) {
			e.printStackTrace();
			log.error(e);
			ResultObj robj = new ResultObj(ResultCode.RESULT_EXCEPTION, "网络异常",null);
			return robj.toString();
		}
	}
}





